﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Common;

namespace DataLayer
{
    public static class DatPago
    {
        /// <summary>
        /// Devuelve que fecha corresponde
        /// </summary>
        /// <param name="tipoFecha">0 desde, 1 hasta, 2 ambos</param>
        /// <param name="IdBnf">El beneficiario</param>
        /// <param name="date">la fecha</param>
        /// <returns>0 si se puede, o el Id de pago que se estaria pisando.</returns>
        public static int ValidateDate(int tipoFecha, int IdBnf, DateTime date)
        {
            List<Util.DBParameter> parameters = new List<Util.DBParameter>();
            parameters.Add(new Util.DBParameter("@tipoFecha", tipoFecha, System.Data.DbType.Int32));
            parameters.Add(new Util.DBParameter("@idBenef", IdBnf, System.Data.DbType.Int32));
            parameters.Add(new Util.DBParameter("@fecha", date, System.Data.DbType.DateTime));
            SqlCommand miCommand = Util.SQLCommandBuild("ValidateFechaPago", parameters);

            return int.Parse(miCommand.ExecuteScalar().ToString());
        }

        public static int ValidateDate(int IdBnf, DateTime from, DateTime to)
        {
            List<Util.DBParameter> parameters = new List<Util.DBParameter>();
            parameters.Add(new Util.DBParameter("@tipoFecha", 2, System.Data.DbType.Int32));
            parameters.Add(new Util.DBParameter("@idBenef", IdBnf, System.Data.DbType.Int32));
            parameters.Add(new Util.DBParameter("@fecha", from, System.Data.DbType.DateTime));
            parameters.Add(new Util.DBParameter("@fecha2", to, System.Data.DbType.DateTime));
            SqlCommand miCommand = Util.SQLCommandBuild("ValidateFechaPago", parameters);

            return int.Parse(miCommand.ExecuteScalar().ToString());
        }

        public static dsBoleto PagoGet(int idBnf, DateTime from, DateTime to)
        {
            List<Util.DBParameter> parameters = new List<Util.DBParameter>();
            parameters.Add(new Util.DBParameter("@IdBenef", idBnf, System.Data.DbType.Int32));
            parameters.Add(new Util.DBParameter("@FchDesde", from, System.Data.DbType.DateTime));
            parameters.Add(new Util.DBParameter("@FchHasta", to, System.Data.DbType.DateTime));

            return Util.SelectSPtoDatasetSolve(Util.SQLCommandBuild("PagoGet", parameters), new string[] { "Compra" });
        }

        public static void PagoSet(int idBnf, DateTime from, DateTime to)
        {
            List<Util.DBParameter> parameters = new List<Util.DBParameter>();
            parameters.Add(new Util.DBParameter("@IdBenef", idBnf, System.Data.DbType.Int32));
            parameters.Add(new Util.DBParameter("@FchDesde", from, System.Data.DbType.DateTime));
            parameters.Add(new Util.DBParameter("@FchHasta", to, System.Data.DbType.DateTime));
            Util.SQLCommandBuild("PagoSet", parameters).ExecuteNonQuery();
        }
    }
}
